package com.example.venadaoa.tool;

import android.content.Context;
import android.content.DialogInterface;

import com.example.venadaoa.R;

import org.apache.http.client.HttpClient;

/**
 * Created by Dell on 2017/7/13.
 */

public class MyLoadingDialog {
    public boolean mCancel = false;
    private HttpClient mHttpClient;
    private Context context;
    private CProgressDialog mDialog;
    private XListView list = null;

    public MyLoadingDialog(Context context, HttpClient mHttpClient, String content, boolean iscancel) {
        this.context = context;
        this.mHttpClient = mHttpClient;
        this.mCancel = iscancel;

//		mDialog = ProgressDialog.show(context,null,content,false,true);
        mDialog = new CProgressDialog(context, R.style.CustomDialog);
        mDialog.setMessage(content);
        mDialog.show();
        init();
    }

    public void init() {

        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

            @Override
            public void onCancel(DialogInterface arg0) {
                // TODO Auto-generated method stub
                cancel();
            }
        });
    }

    public void cancel() {
        if (mCancel) {
            return;
        }
        dimiss();
        mCancel = true;
        if (mHttpClient != null) {
            mHttpClient.getConnectionManager().shutdown();
        }

        //LinkHelp.shutdownHttpClient();
        if (list != null) {
            list.stopRefresh();
            list.stopLoadMore();
        }

    }

    public void setPullToRefreshListView(XListView list) {
        this.list = list;
    }


    public void dimiss() {
        mDialog.dismiss();
    }

    public void show() {
        mDialog.show();
    }

}
